package com.sicau.socialpracticesystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sicau.socialpracticesystem.entity.param.PageParam;
import com.sicau.socialpracticesystem.entity.param.practicetype.PracticeTypeQueryParam;
import com.sicau.socialpracticesystem.entity.po.PracticeType;
import com.sicau.socialpracticesystem.entity.vo.PageDataVO;
import com.sicau.socialpracticesystem.entity.vo.practicetype.PracticeTypeVO;
import com.sicau.socialpracticesystem.mapper.PracticeTypeMapper;
import com.sicau.socialpracticesystem.mapper.VOMapper;
import com.sicau.socialpracticesystem.service.PracticeTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sicau.socialpracticesystem.util.PageUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 社会实践类型表 服务实现类
 * </p>
 *
 * @author sxt && ttxxi
 * @since 2021-04-26
 */
@Service
public class PracticeTypeServiceImpl extends ServiceImpl<PracticeTypeMapper, PracticeType> implements PracticeTypeService {

    @Resource
    private VOMapper.PracticeTypeVOMapper practiceTypeVOMapper;


    @Override
    public List<PracticeTypeVO> queryPrizeByConditions(PracticeTypeQueryParam practiceTypeQueryParam) {
        return practiceTypeVOMapper.selectList(new LambdaQueryWrapper<PracticeTypeVO>()
                .like(practiceTypeQueryParam.getType() != null, PracticeTypeVO::getType, practiceTypeQueryParam.getType())
                .orderByDesc(PracticeTypeVO::getId));
    }

    @Override
    public PageDataVO<PracticeTypeVO> queryPrizeByConditions(PracticeTypeQueryParam practiceTypeQueryParam, PageParam pageParam) {
        Page<PracticeTypeVO> practiceTypeVOPage = practiceTypeVOMapper.selectPage(new Page<>(pageParam.getCurrentPage(), pageParam.getPageSize()), new LambdaQueryWrapper<PracticeTypeVO>()
                .like(practiceTypeQueryParam.getType() != null, PracticeTypeVO::getType, practiceTypeQueryParam.getType())
                .orderByDesc(PracticeTypeVO::getId));
        return PageUtil.convert(practiceTypeVOPage);
    }
}
